﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iNet.Media.Imaging
{
	/// <summary>
	/// ICO 影像解碼工作工廠。
	/// </summary>
	public class IcoImageDecodeTaskFactory : FastImageDecodeTaskFactory
	{
		#region 建構子
		/// <summary>
		/// 初始化新的 IcoImageDecodeTaskFactory 執行個體。
		/// </summary>
		public IcoImageDecodeTaskFactory()
			: base("ICO Image DecodeTask Factory", ImageFormats.Ico)
		{ }
		#endregion
		#region CreateDecodeTask
		public override MediaDecodeTask CreateDecodeTask(MediaStorage source)
		{
			return new IcoImageDecodeTask(source);
		}
		#endregion
		#region IsSupportedFormatCore
		protected override bool IsSupportedFormatCore(byte[] mediaHeader)
		{
			if (mediaHeader.Length < 4)
				return false;
			if (mediaHeader[0] != 0 || mediaHeader[1] != 0)
				return false;
			int imageType = BitConverter.LittleEndian.ToUInt16(mediaHeader, 2);
			if (imageType != 1 && imageType != 2)
				return false;
			return true;
		}
		#endregion
		#region MediaHeaderSize
		public override int MediaHeaderSize
		{
			get
			{
				return 4;
			}
		}
		#endregion
	}
}
